﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SqlServer;
using System.Data;
using System.Data.SqlClient;

namespace DBConnectConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            SqlConnectionStringBuilder connectionBuilder = new SqlConnectionStringBuilder();
            connectionBuilder.DataSource = "Anwasha-PC\\SqlExpress";//server name
            connectionBuilder.InitialCatalog = "wdmsg8";//db name
            connectionBuilder.UserID = "rumi";
            connectionBuilder.Password = "rumi";
            //Sql Server Configuration Manager -> Network Configuration -> Protocols for SQLExpress 
            //Enable ( Shared Memory, Named Pipes, TCP/IP)
            //Restart Sql Server Services -> Sql Server
            
            SqlConnection con = new SqlConnection(connectionBuilder.ConnectionString);
            con.Open();
            //con.BeginTransaction();
            String sql = "Select * from dbo.Users";
            SqlDataAdapter da = new SqlDataAdapter(sql, con);
            DataSet d = new DataSet();
            da.Fill(d);
            
            Console.WriteLine("Connection String: " + con.ConnectionString);
            Console.WriteLine("Database: " + con.Database);
            Console.WriteLine("Data Source: " + con.DataSource);
            con.Close();
        }
    }
}
